﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Golos.Users.UserCache
{
    public partial class Cache
    {
        public bool UserIdExist(Guid userId)
        {
            lock (users)
            {
                return users.ContainsKey(userId);
            }
        }

        public bool UserIdExist(UserIdType idType, string identificationId)
        {
            lock (users)
            {
                foreach (var userId in users.Keys)
                {
                    if(!users[userId].UserIdentification.ContainsKey(idType))
                        continue;
                    if (users[userId].UserIdentification[idType] != identificationId)
                        continue;
                    return true;
                }
                return false;
            }
        }

        public Guid? GetUserId(UserIdType idType, string identificationId)
        {
            lock (users)
            {
                foreach (var userId in users.Keys)
                {
                    if (!users[userId].UserIdentification.ContainsKey(idType))
                        continue;
                    if (users[userId].UserIdentification[idType] != identificationId)
                        continue;
                    return userId;
                }
                return null;
            }
        }

        public UserInfo GetUserInfo(Guid userId)
        {
            lock (users)
            {
                if (!users.ContainsKey(userId))
                    return null;
                return users[userId];
            }
        }
    }
}
